package com.java46.struts2.order.action;

import com.java46.struts2.base.action.BaseAction;
import com.java46.struts2.base.entity.PageEntity;
import com.java46.struts2.base.exception.BusinessException;
import com.java46.struts2.order.service.OrderService;
import org.apache.struts2.convention.annotation.Action;

import java.util.List;

/**
 * @ClassName OrderAction
 * @Description 订单操作
 * @Author zuxia
 * @Date 2018/7/18 9:20
 * @Vcrsion 1.0
 **/
public class OrderAction extends BaseAction {
    
    /**
    *@Author xiao
    *@Description //分页查询订单可加关键字
    *@Date 9:28 2018/7/18
    *@Param []
    *@return void
    */
    @Action(value = "queryorder")
    public String queryOrder(){
        String pagesize="";
        //获取页条数
        try {
            pagesize = request.getParameter("pagesize");
        }catch (Exception e){
            pagesize="";
        }
        String keyword="";
        //获取关键字
        try {
            keyword = request.getParameter("keyword");
        }catch (Exception e){
            keyword="";
        }
        String pageno="";
        //获取页码
        try {
            pageno = request.getParameter("pageno");
        }catch (Exception e){
            pageno="1";
        }
        PageEntity pageEntity = OrderService.queryOrder(pageno, pagesize, keyword);
        setSuccesResult(pageEntity);
        return "json";
    }

   /**
   *@Author xiao
   *@Description //根据订单编号删除订单
   *@Date 11:38 2018/7/18
   *@Param []
   *@return void
   */
   @Action(value = "deleteorder")
    public void deleteOrder(){
       String orderid=null;
        //获取前台订单编号
       try {
           orderid = request.getParameter("orderid");
       }catch (Exception e){
           throw new BusinessException("没有接收到订单数据");
       }
        OrderService.deleteOrder(orderid);
    }

    @Action(value = "addorder")
    /**
     *@Author xiao
     *@Description //生成订单
     *@Date 11:22 2018/7/19
     *@Param []
     *@return java.lang.String
     */
    public String addOrder(){
        String uId="";
        String tableNo="";
        String pNum="";
        String remark="";
        String totalMoney="";
        String dishesStr="";
        try {
            uId = request.getParameter("uid");
            tableNo = request.getParameter("tableNo");
            pNum = request.getParameter("pNum");
            remark = request.getParameter("remark");
            totalMoney = request.getParameter("totalMoney");
            dishesStr = request.getParameter("dishesStr");
        }catch (Exception e){
            throw new BusinessException("没有接收到数据");
        }
        String orderno = OrderService.addUserOrder(uId, tableNo, pNum, remark, totalMoney, dishesStr);
        setSuccesResult(orderno);
        return "json";
    }

    /**
     * @Author xiaobo
     * @Description //查询用户订单
     * @Date 22:36 2018/7/19 0019
     * @Param []
     * @return java.lang.String
     */
    @Action(value = "queryuserorder")
    public String queryUserOrder(){
        String uSign="";
        String struts="";

        try {
            uSign = request.getParameter("uid");
            struts = request.getParameter("struts");
        }catch (Exception e){
            throw new BusinessException("没有接收到用户数据");
        }
        List list = OrderService.queryUserOrder(uSign, struts);
        setSuccesResult(list);
        return "json";
    }

    /**
    *@Author xiao
    *@Description //根据订单号查询订单信息
    *@Date 18:59 2018/7/20
    *@Param []
    *@return java.lang.String
    */
    @Action(value = "queryOrderNo")
    public  String queryOrderNo(){
        String orderNo="";
        try{
            orderNo = request.getParameter("orderNo");
        }catch (Exception e){
            throw new BusinessException("没有接收到订单号");
        }
        List list = OrderService.queryOrderNO(orderNo);
        setSuccesResult(list);
        return "json";
    }

    /**
    *@Author xiao
    *@Description //修改订单状态
    *@Date 19:06 2018/7/20
    *@Param []
    *@return void
    */
    @Action(value = "updateOrderState")
    public void updateOrderState(){
        String orderId="";
        String payType="";
        String struts="";
        try{
            orderId = request.getParameter("orderId");

            struts = request.getParameter("struts");
        }catch (Exception e){
            throw new BusinessException("没有接收到数据");
        }

        try{
            payType = request.getParameter("payType");
        }catch (Exception e){
            e.printStackTrace();
        }

        OrderService.updateOrderState(orderId,payType,struts);
    }

}
